#!/usr/bin/env node

var p = require('procstreams');
var serviceName = 'httpd';
var interval = 5000; //1000 * 60 * 2;
setInterval(function () {
    p("ps aux").pipe('grep -i ' + serviceName).data(function (err, stdout, stderr) {
        if(!!stdout && stdout.indexOf(serviceName)) {
            console.log('exist,don\'t need restart');
            console.log(stdout.toString());
        } else {
            console.log('restart,waiting...');
            p('sudo /usr/local/bin/httpd -k restart', function (stdout, stderror) {});
        }
    });
}, interval);

